package com.by.zhdoctor.huanxin.api.impl;

import com.by.zhdoctor.huanxin.api.SendMsgApi;
import com.by.zhdoctor.huanxin.util.HuanXinInfo;
import com.by.zhdoctor.huanxin.util.ResponseHandler;
import com.by.zhdoctor.huanxin.util.TokenUtil;
import io.swagger.client.ApiResponse;
import io.swagger.client.api.MessagesApi;
import io.swagger.client.model.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 消息发送api调用接口的实现类,该实现类可以发送任何类型的消息，只要环信支持
 * 但是必须是在调用方传入对于的拓展MsgContent
 * Created by succy on 17-9-3.
 */
@Service
public class SendMsgApiImpl implements SendMsgApi {
    @Autowired
    private ResponseHandler responseHandler;

    private MessagesApi api = new MessagesApi();

    @Override
    public ApiResponse<?> sendMsg(final Msg msg) {
        return responseHandler.handle(() ->
            api.orgNameAppNameMessagesPostWithHttpInfo(HuanXinInfo.ORG_NAME, HuanXinInfo.APP_NAME, TokenUtil.getAccessToken(), msg));
    }
}
